import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:zootix/constants/zt_cache_key.dart';
import 'package:zootix/screens/mine/zt_mine.controller.dart';
import 'package:zootix/services/zt_app_info.service.dart';
import 'package:zootix/services/zt_storage.service.dart';
import 'package:zootix/util/zt_screen_adaper_util.dart';
import 'package:zootix/zt_config.dart';

class ZtMineAboutPage extends StatelessWidget {
  final _controller = Get.find<ZtMineController>();
  ZtMineAboutPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: ZtScreenAdaper.width(15)),
      child: ListView.separated(
          separatorBuilder: (context, index) => const Divider(
                color: Color(0xFFCCCCCC),
              ),
          itemBuilder: ((context, index) => InkWell(
                onTap: () async {
                  if (index == 1) {
                    launchUrl(Uri.parse(ZtGloablConfig.TERM_OF_USER));
                  }
                  if (index == 2) {
                    launchUrl(Uri.parse(ZtGloablConfig.PRIVACY_POLICY));
                  }
                  if (index == 3) {
                    if (await canLaunchUrl(
                        Uri.parse(ZtGloablConfig.APPLE_STORE_PAGE))) {
                      launchUrl(Uri.parse(ZtGloablConfig.APPLE_STORE_PAGE));
                    } else {
                      throw 'Can\'t open it.';
                    }
                  }
                },
                child: Container(
                  padding:
                      EdgeInsets.symmetric(vertical: ZtScreenAdaper.width(10)),
                  child: Row(
                    children: [
                      Text(
                        _controller.aboutList[index].title,
                        style: TextStyle(fontSize: ZtScreenAdaper.sp(18)),
                      ),
                      Spacer(),
                      if (_controller.aboutList[index].title == 'Version')
                        Text(
                            '${ZtStorageService.to.getString(ZtCacheKeys.ver, isWithUser: false)}')
                    ],
                  ),
                ),
              )),
          itemCount: 3),
    );
  }
}
